package com.yk.web.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.yk.common.annotation.Log;
import com.yk.common.enums.BusinessType;
import com.yk.course.domain.CourseInfo;
import com.yk.course.service.ICourseInfoService;
import com.yk.common.core.controller.BaseController;
import com.yk.common.core.domain.AjaxResult;
import com.yk.common.utils.poi.ExcelUtil;
import com.yk.common.core.page.TableDataInfo;
import org.springframework.stereotype.Controller;

/**
 * 课程设置Controller
 * 
 * @author xufei
 * @date 2025-04-28
 */
@Controller
@RequestMapping("/course/courseInfo")
public class CourseInfoController extends BaseController
{
    private String prefix = "course/courseInfo";

    @Autowired
    private ICourseInfoService courseInfoService;

    @RequiresPermissions("course:courseInfo:view")
    @GetMapping()
    public String courseInfo()
    {
        return prefix + "/courseInfo";
    }

    /**
     * 查询课程设置列表
     */
    @RequiresPermissions("course:courseInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourseInfo courseInfo)
    {
        startPage();
        List<CourseInfo> list = courseInfoService.selectCourseInfoList(courseInfo);
        return getDataTable(list);
    }

    /**
     * 导出课程设置列表
     */
    @RequiresPermissions("course:courseInfo:export")
    @Log(title = "课程设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourseInfo courseInfo)
    {
        List<CourseInfo> list = courseInfoService.selectCourseInfoList(courseInfo);
        ExcelUtil<CourseInfo> util = new ExcelUtil<CourseInfo>(CourseInfo.class);
        return util.exportExcel(list, "课程设置数据");
    }

    /**
     * 新增课程设置
     */
    @RequiresPermissions("course:courseInfo:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存课程设置
     */
    @RequiresPermissions("course:courseInfo:add")
    @Log(title = "课程设置", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourseInfo courseInfo)
    {
        return toAjax(courseInfoService.insertCourseInfo(courseInfo));
    }

    /**
     * 修改课程设置
     */
    @RequiresPermissions("course:courseInfo:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        CourseInfo courseInfo = courseInfoService.selectCourseInfoById(id);
        mmap.put("courseInfo", courseInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存课程设置
     */
    @RequiresPermissions("course:courseInfo:edit")
    @Log(title = "课程设置", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourseInfo courseInfo)
    {
        return toAjax(courseInfoService.updateCourseInfo(courseInfo));
    }

    /**
     * 删除课程设置
     */
    @RequiresPermissions("course:courseInfo:remove")
    @Log(title = "课程设置", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courseInfoService.deleteCourseInfoByIds(ids));
    }
}
